package com.zhp.listener;

import com.zhp.pojo.HType;
import com.zhp.service.HtypeService;
import com.zhp.service.impl.HtypeServiceImpl;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import java.util.List;

/**
 * @date 2023/4/11
 * @desc  监听servletContext的监听器
 */
@WebListener
public class AppListener implements ServletContextListener {

    @Override
    public void contextInitialized(ServletContextEvent sce) {

        System.out.println("应用初始化");
        //准备数据字典数据
        HtypeService htypeService = new HtypeServiceImpl();
        List<HType> typeList =  htypeService.findAllTypes();
        //放到最大的域对象中
        ServletContext servletContext = sce.getServletContext();

        servletContext.setAttribute("ts",typeList);

    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {

    }
}
